package com.s2paganini.events.Keyboard
{
	import com.s2paganini.core.ICommand;
	
	import flash.display.Stage;
	import flash.events.KeyboardEvent;		

	/**
	 * @author siLvio paganini | s2paganini.com
	 * @purpose Invoker Keyboard
	 */

	public class InvokerKeyboard 
	{
		private var stage : Stage;
		private var keyList : Array;
		private var commandList : Array;

		/**
		 * @param _stage Stage Reference
		 */
		public function InvokerKeyboard(_stage : Stage)
		{
			this.keyList = new Array();
			this.commandList = new Array();
			stage = _stage;
			stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyPress);
		}

		public function setCommand(keyDown : uint, c : ICommand) : void
		{
			this.keyList.push(keyDown);
			this.commandList.push(c);
		}

		private function onKeyPress(event : KeyboardEvent) : void
		{
			for (var i : int = 0; i< keyList.length; i++){
				if(keyList[i] == event.keyCode){
					this.commandList[i].execute();
					break;
				}	
			}
		}
	}
}
